package com.songVersion.model;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class NestCache
{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private String title;
	
	@Persistent
	private String author;

	@Persistent
	private int pageNumber;
	
	
	@Persistent
	private List<Song> songs;
	
	public NestCache(String title, String author, int pageNumber)
	{
		super();
		this.title = title;
		this.author = author;
		this.pageNumber = pageNumber;
	}

	public NestCache(NestCache nestCache)
	{
		this.key = nestCache.getKey();
		this.title = nestCache.getTitle();
		this.author = nestCache.getAuthor();
		this.pageNumber = nestCache.getPageNumber();
		this.songs = cloneSongs(nestCache.getSongs());
	}

	private List<Song> cloneSongs(List<Song> songs2)
	{
		List<Song> newSongs = new ArrayList<Song>();
		for (Song s:songs2)
		{
			Song newSong = new Song(s);
			
			newSongs.add(newSong);
		}
		return newSongs;
	}

	public Key getKey()
	{
		return key;
	}

	public void setKey(Key key)
	{
		this.key = key;
	}

	public String getTitle()
	{
		return title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

	public String getAuthor()
	{
		return author;
	}

	public void setAuthor(String author)
	{
		this.author = author;
	}

	public List<Song> getSongs()
	{
		return songs;
	}

	public void setSongs(List<Song> songs)
	{
		this.songs = songs;
	}

	public int getPageNumber()
	{
		return pageNumber;
	}

	public void setPageNumber(int pageNumber)
	{
		this.pageNumber = pageNumber;
	}

}
